
# 直接修复脚本
with open(r'd:\未知\yolo_apply\video_processing\video_processor_final.py', 'r', encoding='utf-8') as f:
    lines = f.readlines()

# 找到问题区域
problem_start = -1
problem_end = -1
for i, line in enumerate(lines):
    if '# 错误率过高时触发警告和恢复' in line:
        problem_start = i
    elif problem_start != -1 and 'error_count = 0' in line:
        problem_end = i
        break

print(f"问题区域从第{problem_start+1}行到第{problem_end+1}行")

# 创建一个新的文件内容列表
new_lines = []

# 添加问题区域之前的所有行
for line in lines[:problem_start]:
    new_lines.append(line)

# 添加注释和重置错误计数
# 保持与周围代码相同的缩进
if problem_start > 0:
    prev_line = lines[problem_start-1]
    indent = ' ' * (len(prev_line) - len(prev_line.lstrip()))
else:
    indent = ''

new_lines.append(indent + '# 错误率过高时触发警告和恢复\n')
new_lines.append(indent + 'error_count = 0\n')

# 添加问题区域之后的所有行
for line in lines[problem_end+1:]:
    new_lines.append(line)

# 写回文件
with open(r'd:\未知\yolo_apply\video_processing\video_processor_final.py', 'w', encoding='utf-8', newline='\n') as f:
    f.writelines(new_lines)

print("已直接修复问题区域")
